public class Demo5 {
    public static Object  locker1=new Object();
    public static Object  locker2=new Object();
    public static void main(String[] args) {
        Thread t1=new Thread(new Runnable() {
            @Override
            public synchronized void run() {
                synchronized (locker1) {
                    System.out.println("s1.start");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    synchronized (locker2) {
                        System.out.println("s2.over");
                    }
                }
            }
        });
       t1.start();
        Thread t2=new Thread(new Runnable() {
            @Override
            public synchronized void run() {
                synchronized (locker2) {
                    System.out.println("t2.start");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    synchronized (locker1) {
                        System.out.println("t1.over");
                    }
                }
            }
        });
        t2.start();
    }
}
